package com.itsu.admin.controller;

import com.itsu.admin.model.ListResult;
import com.itsu.admin.mvc.Result;
import com.itsu.admin.service.NodeService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

import java.util.List;
import java.util.Map;

/**
 * @author Jerry.Su
 * @Date 2022/2/9 16:14
 */
@RestController
@RequestMapping("/node")
public class NodeController {

    @Resource
    private NodeService nodeService;

    @GetMapping("/list")
    public ListResult allNodes() {
        List<Map<String, String>> allNodes = nodeService.getAllNodes();
        ListResult listResult = new ListResult();
        listResult.setCount(allNodes.size());
        listResult.setCode(0);
        listResult.setData(allNodes);
        return listResult;
    }

    @PostMapping("/up")
    public Result up(String node) {
        String msg = nodeService.upNode(node);
        return Result.ok(msg);
    }

    @PostMapping("/down")
    public Result down(String node) {
        String msg = nodeService.downNode(node);
        return Result.ok(msg);
    }
}
